//
//  UIImage+MapUIImage.m
//  Kjs
//
//  Created by maple on 16/4/17.
//  Copyright © 2016年 kjs. All rights reserved.
//

#import "UIImage+MapUIImage.h"


@implementation UIImage (MapUIImage)

+ (UIImage *)drawArrowWithDirection:(DirectionType)direction {
    UIImage *arrowImage = nil;
    
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(20, 20), NO, 0);
    CGPoint startPoint, centerPoint, endPoint;
    if(direction == DirectionTypeUp || direction == DirectionTypeDown) {
        startPoint = CGPointMake(0, 10);
        endPoint = CGPointMake(20, 10);
        centerPoint = direction == DirectionTypeUp ? CGPointMake(10, 0): CGPointMake(10, 20);
    }
    else {
        startPoint = CGPointMake(10, 0);
        endPoint = CGPointMake(10, 20);
        centerPoint = direction == DirectionTypeLeft ? CGPointMake(0, 10): CGPointMake(20, 10);
    }
    UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
    UIColor *lineColor = [UIColor colorWithRed:228.0/255 green:228.0/255 blue:228.0/255 alpha:1];
    [lineColor setStroke];
    bezierPath.lineWidth = 1.5;
    [bezierPath moveToPoint:startPoint];
    [bezierPath addLineToPoint:centerPoint];
    //    [bezierPath moveToPoint:centerPoint];
    [bezierPath addLineToPoint:endPoint];
    [bezierPath stroke];
    arrowImage = UIGraphicsGetImageFromCurrentImageContext();
    
    return arrowImage;
}

+ (UIImage *)drawTickWithColor:(UIColor *)tickColor {
    UIImage *tickImage = nil;
    
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(50, 50), NO, 0);
    UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
    CGPoint startPoint = CGPointMake(10, 30);
    CGPoint centerPoint = CGPointMake(20, 40);
    CGPoint endPoint = CGPointMake(40, 15);
    bezierPath.lineWidth = 5;
    bezierPath.lineCapStyle = kCGLineCapRound;
    bezierPath.lineJoinStyle = kCGLineJoinRound;
    [bezierPath moveToPoint:startPoint];
    [bezierPath addLineToPoint:centerPoint];
    [bezierPath addLineToPoint:endPoint];
    [tickColor setStroke];
    [bezierPath stroke];
    tickImage = UIGraphicsGetImageFromCurrentImageContext();
    
    return tickImage;
}

@end
